package com.hht.tools.baselib

import androidx.recyclerview.widget.RecyclerView
import com.hht.baselibs.activity.BaseActivity
import com.hht.baselibs.adapter.CommonAdapter
import com.hht.baselibs.layoutManager.LayoutManagerHelper
import com.hht.baselibs.layoutManager.RecycleViewPagerConfig
import com.hht.toolanduilibs.showLog
import com.hht.tools.R
import com.hht.tools.databinding.BaseLibsUiItemsBinding
import com.hht.tools.databinding.BaseLibsUisBinding

class BaseLibsUI : BaseActivity<BaseLibViewModel, BaseLibsUisBinding>() {
    private var appList = ArrayList<AppBean>()
    private lateinit var appAdapter: CommonAdapter<BaseLibsUiItemsBinding, AppBean>

    override fun getLayoutResId(): Int {
        return R.layout.base_libs_uis
    }

    override fun initView() {
        super.initView()
        appList.addAll(PackageManagerUtils.getAllApkList())
        appAdapter = CommonAdapter<BaseLibsUiItemsBinding, AppBean>().setAdapterDataList(appList)
            .setLayoutResId(R.layout.base_libs_ui_items)
            .setViewModelBindBean { baseLibsUiItemBinding, appBean ->
                baseLibsUiItemBinding.appBean = appBean
            }
            .setOnItemClickListener {
                "setOnItemClickListener, itemBean==$it".showLog()
                mContext.startActivity(it.getIntent())
            }
        RecycleViewPagerConfig.setFlingThreshold(501)
        RecycleViewPagerConfig.setMillisecondsPreInch(31f)

        LayoutManagerHelper.newInstance().setRows(3).setColumns(4)
            .setOrientation(RecyclerView.HORIZONTAL)
            .bindRecycleView(viewDataBing.baseLibRecycleView,viewDataBing.baseLibIndicatorView,false)
        viewDataBing.baseLibRecycleView.adapter = appAdapter
    }

    override fun initObserve() {
        mViewModel.appListData().observe(this) {
            appList.clear()
            appList.addAll(it)
            appAdapter.notifyDataSetChanged()
        }
    }
}